<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>AllyFolio | Block Settings </title>
<?php include_once("common_script_inclusions.php"); ?>
</head>
<body>
<?php
require_once("includes/pagetop.php");
if(isset($_SESSION['Allyfolio_User_ID']))
{   
    if($_SESSION['Allyfolio_User_ID']<0){
        redirect("accountblocked.php");    
    }
}
else{
    redirect("index.php");
}
include_once("updates/CommonFeatures.php");

$loggedUserObj=new UserDetails();
if (!isset($_SESSION["User_details"])){
    $_SESSION["Privacy_Settings"]=$loggedUserObj->getUserPrivacyDetails($_SESSION["Allyfolio_User_ID"]);
}
//echo "<pre>";
//print_r($_SESSION["Privacy_Settings"]);
?>
	<div id="main_wrapper">
    <!--=================Header Start=======================-->
	<div class="wrapper row1">
	<div class="header">
    	<div class="log_button">
		<table width="744" border="0" style="margin-top:5px;">
			<tr>
				<td width="24">
					<a href="#"><img src="images/navico_1.png" /></a>				</td>
				<td width="36">
					<a href="#"><img src="images/navico_2.png" /></a>				</td>
				<td width="26">
					<a href="#"><img src="images/navico_3.png" /></a>				</td>
				<td width="30">
					<a href="#"><img src="images/navico_4.png" /></a>				</td>
					<td width="594">
					<!--<ul class="dn_txt3">
						<li><img src="images/dna_txt_right.png" /></li>
						<li><input type="text" class="dna_txt2" /></li>
						<li><img src="images/dna_txt_left.png" /></li>
					</ul>-->
					
					</td>
			</tr>
		  </table>
		</div>
		
       
    	
        <a href="index.html" class="logo"></a>
    </div>
    <div class="clearfix"></div>  
    
    
    </div>
    <div class="clearfix"></div>
    <!--=================Header end=======================-->
    
    
    
    <!--=================Body Contain Start=======================-->
    <div class="wrapper">
      <div class="header acSetting">
          <h1>Settings</h1>
    <table cellpadding="0" cellspacing="0" width="100%">
                <tr>
                    <td style="vertical-align: top;">
                          <div >
                          <?php  
                          include_once("settings_menu.php");
                          include_once("includes/common_snippets.php");
                          ?>
                          </div>
                    </td>
                    <td style="vertical-align: top;">
                            <?php
                            $oDropfilters= new CGetFilters();
                            $privacyTypes=$oDropfilters->getFilters("privacy_types",1,true);
                            ?>  
                        <form name="frmblocksettings" id="frmblocksettings" action="ajax/generic_crudoperations.php">
                             <div class="acSettingSecR">
                                  <div class="fieldSec">
                                    <label class="w316">Enclosing Tagging permission</label> 
                                    <select id="block_permission_settings" id="block_permission_settings" >
                                    <?php
                                    $myprivacysetting=0;
                                    if (!empty($_SESSION["Privacy_Settings"])) {
                                        $myprivacysetting = trim($_SESSION["Privacy_Settings"]["block_permission"]);
                                    }
                                    if(is_numeric($myprivacysetting) && $myprivacysetting>0){
                                        $defaultSelected=$myprivacysetting;
                                    }
                                    else{
                                        $defaultSelected=1; //privacy type assigned    
                                    }
                                    foreach($privacyTypes as $privacyType){
                                        if($privacyType["ID"]==$defaultSelected){
                                            $selected=true;
                                        }
                                        else if($privacyType["keyword"]=="public"){
                                            $selected=true;
                                        }
                                        else{
                                            $selected=false;
                                        }
                                        /*
                                        switch($privacyType["keyword"]){
                                            case "friends":
                                            case "choose_cluster":
                                            case "specific_friend":
                                            case "only_me":
                                                continue;
                                                break;
                                            default:
                                            */
                                        ?>
                                        <option value="<?php echo $privacyType["ID"] ?>" <?php if($selected){  ?>selected="true" <?php } ?> >
                                            <?php echo $privacyType["Privacy_Type_Title"]; ?> 
                                        </option>
                                        <?php
                                        /*}*/    
                                        
                                    }
                                    ?>
                                </select>
                                  </div>
                                  <div class="fieldSec">
                                    <label class="w316">Block User for tagging.</label> 
                                    <input type="text" placeholder="Enter User name / E-mail / Phone No." id="blockidfield" class="txtCenter" onchange="return getBlUBLList('friends',this.value);" style="width:300px;" />
                                  </div>
                                  <div class="fieldSec" id="friendsDiv">
                                 </div>
                                <br />
                                <br />
                                <br />
                                <br />
         
               
                                <div class="fieldSec">
                                    <label class="w316">Block user for event invitation </label> 
                                    <input type="text" placeholder="Enter User name / E-mail / Phone No."  id="blockeventfield" class="txtCenter" onchange="return getBlUBLList('events',this.value);"   style="width:300px;"/> 
                                </div>
                                <div class="fieldSec" id="eventsDiv">
                                    
                                </div>
                            </div>
                    </form>
                </td>
            </tr>
     </table>
     </div>
     </div>
     
   
    
    
    <div class="clearfix"></div>
    <script type="text/javascript">
    
    var blocktypeval="";
    var searchBlockTxt="";
    
    $("select").change(function(e){
        var idClicked = e.target.id;
        changePrivacySettings(idClicked,$("#"+idClicked).val());
    });

    function changePrivacySettings(sFor,iVal){
        var urlstr = $("#frmblocksettings").attr( "action" );
        //alert("sfor: "+sFor+" iVal "+iVal);
        $.ajax({
    	  	type: "POST",
    	  	url: urlstr,
    	  	cache: false,
    	  	data: { 
    	  	         "actiontype":"update_userprivacy_settings",   
    	  	         "sFor": sFor,                                     
                     "iVal": iVal
                  } 
        })
    	.done(function( data ) {	
    	   //alert(data);
    	   var jsonParsed=$.parseJSON(data);
            console.log(jsonParsed);
            /*if(document.getElementById("errconsole")){
                document.getElementById("errconsole").innerHTML=data;
            }*/
            if(!isNaN(jsonParsed.err)){ //means have some code
                switch(parseInt(jsonParsed.err)){
                    case 200:
                            //alert(jsonParsed.msg);
                            break;
                    default:
                            alert(jsonParsed.msg);
                            break;
                }
            }
    	})
    	.fail(function(msg) { 
    		console.log(msg);
    //		alert("error"); 
    	})
        .always(function() { 
    		//alert("complete"); 
    	});
    }
    
    function getBlUBLList(type,txtVal)
    {
        blocktypeval=type;
        searchBlockTxt=txtVal;
        
        if(trim(txtVal)!='')
        {
            //alert("ajax_search/ajaxGetList.php?action="+type+"&searchVal="+txtVal);
            //console.log("ajax_search/ajaxGetList.php?action="+type+"&searchVal="+txtVal);
            $.ajax({
              cache:false,  
              async:false,
              url: "ajax_search/ajaxGetList.php?action="+type+"&searchVal="+txtVal,
        	  success: function( data ) {
        	    if(trim(data)!='')
                {
                    //alert(data);
                    if(type=="friends")
                    {
                        document.getElementById('friendsDiv').innerHTML=data;
                    }
                    else
                    {
                        document.getElementById('eventsDiv').innerHTML=data;
                    }
                    return false;
                }
                
        	  }
        	});
        }
    }
    
    function changeBlockStatus(tablename,touserid,blubltype)
    {
        if(touserid>0 && tablename!='')
        {
            if(blubltype==0)
            {
                message="Block";
            }
            else
            {
                message="Unblock";
            }
            alertify.confirm("Are you sure, you want to "+message+" this user?", function (e) {
    		    if (e) {
    		        
                    urlval= "ajax_search/ajaxGetList.php?action=Block&tablename="+tablename+"&status="+blubltype+"&touserid="+touserid;
                    $.ajax({
                      cache:false,  
                      async:false,
                      url: urlval,
                	  success: function( data ) {
                	    if(trim(data)=="SUCCESS")
                        {
                            if(trim(searchBlockTxt)!='' && trim(blocktypeval)!='')
                            {
                                getBlUBLList(blocktypeval,searchBlockTxt);
                            }
                            //return false;
                        }
                        else
                        {
                            alertify.alert(data);
                            return false;
                        }
                        
                	  }
                	});
                 } 
                 else 
                 {
    			     alertify.error("You've clicked Cancel");
        		 }
        	});
        	//return false;
        }
    }
    
</script>
 </body>
</html>